package fleditor.view.assetView
{
	import flash.display.Sprite;
	
	import fleditor.common.CommonUtil;
	import fleditor.controller.FlEditorController;
	import fleditor.core.asset.AssetCell;
	import fleditor.core.iso.IsoScene;
	import fleditor.events.AssetEvent;
	import fleditor.model.FlEditorModel;
	
	/**
	 * 物件编辑视图 
	 * @author devin
	 * 
	 */	
	public class AssetSceneView extends Sprite
	{
		private var _controller:FlEditorController;
		private var _model:FlEditorModel;
		private var _scene:IsoScene;//地图资源物件层
		private var _assetCell:AssetCell;//物件单项
		
		/**
		 *物件编辑视图 
		 * @param controller 全局controller类
		 * @param model 全局Model类
		 * 
		 */		
		public function AssetSceneView(controller:FlEditorController, model:FlEditorModel)
		{
			_controller=controller;
			_model=model;
			
			setView();
			setEvent();
		}
		
		/**
		 * 视图设置 
		 * 
		 */		
		private function setView():void
		{
			_scene=new IsoScene();
			addChild(_scene);
		}
		
		/**
		 * 事件设置 
		 * 
		 */		
		private function setEvent():void
		{
			_controller.addEventListener(AssetEvent.ADD_ASSETLIB_TO_ASSET_EDIT_VIEW, __onAddAssetLib);//监听增加物件事件
		}
		
		/**
		 * 增加物件资源库对象事件 
		 * @param evt
		 * 
		 */		
		private function __onAddAssetLib(evt:AssetEvent):void
		{
			if(_assetCell)
			{
				if(_assetCell.parent) _assetCell.parent.removeChild(_assetCell);
				_assetCell.dispose();
			}
			_assetCell=null;
			
			_assetCell=new AssetCell(CommonUtil.getDefinitionByName(evt.date));
			_scene.addAsset(_assetCell);
		}
	}
}